package com.medusa.aps.business.modules.basic.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.medusa.aps.business.model.pagination.Page;
import com.medusa.aps.business.modules.basic.model.input.ClassSystemEquipmentPageParam;
import com.medusa.aps.business.modules.basic.model.input.ClassSystemParam;
import com.medusa.aps.business.modules.basic.model.output.ClassSystemEquipmentModel;
import com.medusa.aps.business.modules.basic.model.output.ClassSystemListModel;
import com.medusa.aps.business.modules.basic.model.output.ClassSystemModel;
import com.medusa.aps.business.modules.basic.mp.entity.ClassSystem;
import com.medusa.aps.business.modules.basic.mp.service.ClassSystemService;
import com.medusa.aps.business.common.model.resp.Result;
import com.medusa.aps.business.common.web.valid.group.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 班制控制层
 *
 * @author yuxh
 * @since 2023-08-14 17:37:43
 */
@Tag(name = "班制控制层")
@RestController
@RequestMapping("/classSystem")
public class ClassSystemController {
    /**
     * 服务对象
     */
    @Resource
    private ClassSystemService classSystemService;

    /**
     * 分页查询所有数据
     *
     * @param queryPage 分页查询参数
     * @return 所有数据
     */
    @GetMapping
    @Operation(description = "分页查询所有数据", method = "GET", summary = "分页查询所有数据")
    public Result<IPage<ClassSystemListModel>> classPage(Page<ClassSystem> queryPage) {
        return Result.ok(
                classSystemService.classPage(queryPage)
        );
    }

    /**
     * 新增班制数据
     *
     * @param classSystem 班制参数
     * @return 新增结果
     */
    @PostMapping("/create")
    @Operation(description = "新增班制", method = "POST", summary = "新增班制")
    public Result<Void> newClass(@RequestBody @Validated ClassSystemParam classSystem) {
        this.classSystemService.newClass(classSystem);
        return Result.ok();
    }

    /**
     * 修改班制数据
     */
    @PutMapping("/update")
    @Operation(description = "修改班制", method = "PUT", summary = "修改数据")
    public Result<Void> updateClass(@RequestBody @Validated(Update.class) ClassSystemParam classSystem) {
        this.classSystemService.updateClass(classSystem);
        return Result.ok();
    }

    /**
     * 班制分页查询设备
     *
     * @return 设备信息
     */
    @Operation(description = "班制分页查询设备", method = "GET", summary = "查询设备")
    @GetMapping("/equipment")
    public Result<IPage<ClassSystemEquipmentModel>> equipmentPage(ClassSystemEquipmentPageParam queryPage) {
        return Result.ok(
                classSystemService.equipmentPage(queryPage)
        );
    }

    /**
     * 通过主键查询班制配置详情
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(description = "通过主键查询班制配置详情", method = "GET", summary = "通过主键查询单条数据")
    @GetMapping("/detail")
    public Result<ClassSystemModel> info(@RequestParam Integer id) {
        return Result.ok(classSystemService.classInfo(id));
    }

    /**
     * 删除数据
     *
     * @param id 主键id
     * @return 删除结果
     */
    @DeleteMapping("/delete")
    @Operation(description = "删除数据", method = "DELETE", summary = "删除数据")
    public Result<Void> delete(@RequestParam Integer id) {
        classSystemService.removeClass(id);
        return Result.ok();
    }

    /**
     * 是否有班制的工作日历正在生成
     *
     * @return 是否存在
     */
    @GetMapping("/generate/working/calendar")
    @Operation(description = "是否有班制的工作日历正在生成")
    public Result<Boolean> isGenerateWorkingCalendar() {
        return Result.ok(classSystemService.isGenerateWorkingCalendar());
    }
}

